home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / SAT 2.4.0 / SAT / Add-ons / Load faces / FaceFromPICT.p < prev    next >
Encoding:
Text File  |  1997-03-05  |  2.8 KB  |  108 lines  |  [TEXT/PJMM]

  1. unit FaceFromPICT;
  2.  
  3. interface
  4.     uses
  5. {$IFC UNDEFINED THINK_PASCAL}
  6.         Types, QuickDraw, Memory, Resources, ToolUtils, 
  7. {$ENDC}
  8.         SAT;
  9.  
  10.     function GetFaceFromPICT (colorPICTid, bwPICTid, maskPICTid: integer): FacePtr;
  11.     function GetFaceFromPICTToRect (colorPICTid, bwPICTid, maskPICTid: integer; bounds: Rect): FacePtr;
  12.  
  13. implementation
  14.  
  15.     function GetFaceFromPICT (colorPICTid, bwPICTid, maskPICTid: integer): FacePtr;
  16.         var
  17.             bounds: Rect;
  18.             thePICT, maskPICT: PicHandle;
  19.             theFace: FacePtr;
  20.             savePort: SATPort;
  21.     begin
  22.         SATGetPort(savePort);
  23.         GetFaceFromPICT := nil; {Degfault return value if something goes wrong}
  24.  
  25. {Get PICTs}
  26. {IDEA: It should really check if the PICT it loads was loaded already, and if it was, don't dispose it.}
  27.         if gSAT.initDepth > 1 then
  28.             thePICT := GetPicture(colorPICTid)
  29.         else
  30.             thePICT := GetPicture(bwPICTid);
  31.         maskPICT := GetPicture(maskPICTid);
  32.  
  33.         if (thePICT = nil) or (maskPICT = nil) then
  34.             exit(GetFaceFromPICT);
  35.  
  36.         bounds := thePICT^^.picFrame;
  37.         OffsetRect(bounds, -bounds.left, -bounds.top);
  38.  
  39. {Create face}
  40.         theFace := SATNewFace(bounds);
  41.         if theFace = nil then
  42.             exit(GetFaceFromPICT);
  43.  
  44. {Draw in the face}
  45.         SATSetPortFace(theFace);
  46.         DrawPicture(thePICT, bounds);
  47.         SATSetPortMask(theFace);
  48.         DrawPicture(maskPICT, bounds);
  49. {Tell SAT that we are done}
  50.         SATChangedFace(theFace);
  51.  
  52. {Get rid of the PICTs}
  53.         ReleaseResource(Handle(thePICT));
  54.         ReleaseResource(Handle(maskPICT));
  55.  
  56. {Return the face.}
  57.         GetFaceFromPICT := theFace;
  58.  
  59.         SATSetPort(savePort);
  60.     end; {GetFaceFromPICT}
  61.  
  62. {Almost the same function, but loads the face to a desired Rect rather than to the picFrame of the PICT.}
  63.     function GetFaceFromPICTToRect (colorPICTid, bwPICTid, maskPICTid: integer; bounds: Rect): FacePtr;
  64.         var
  65.             thePICT, maskPICT: PicHandle;
  66.             theFace: FacePtr;
  67.             savePort: SATPort;
  68.     begin
  69.         SATGetPort(savePort);
  70.         GetFaceFromPICTToRect := nil; {Degfault return value if something goes wrong}
  71.  
  72. {Get PICTs}
  73. {IDEA: It should really check if the PICT it loads was loaded already, and if it was, don't dispose it.}
  74.         if gSAT.initDepth > 1 then
  75.             thePICT := GetPicture(colorPICTid)
  76.         else
  77.             thePICT := GetPicture(bwPICTid);
  78.         maskPICT := GetPicture(maskPICTid);
  79.  
  80.         if (thePICT = nil) or (maskPICT = nil) then
  81.             exit(GetFaceFromPICTToRect);
  82.  
  83.         OffsetRect(bounds, -bounds.left, -bounds.top);
  84.  
  85. {Create face}
  86.         theFace := SATNewFace(bounds);
  87.         if theFace = nil then
  88.             exit(GetFaceFromPICTToRect);
  89.  
  90. {Draw in the face}
  91.         SATSetPortFace(theFace);
  92.         DrawPicture(thePICT, bounds);
  93.         SATSetPortMask(theFace);
  94.         DrawPicture(maskPICT, bounds);
  95. {Tell SAT that we are done}
  96.         SATChangedFace(theFace);
  97.  
  98. {Get rid of the PICTs}
  99.         ReleaseResource(Handle(thePICT));
  100.         ReleaseResource(Handle(maskPICT));
  101.  
  102. {Return the face.}
  103.         GetFaceFromPICTToRect := theFace;
  104.  
  105.         SATSetPort(savePort);
  106.     end; {GetFaceFromPICTToRect}
  107.  
  108. end.